#!/bin/sh
#reset-passwd {旧密码} {新密码} {节点IP}:{节点PORT} {节点IP}:{节点PORT} ...
old_passwd=$1
new_passwd=$2

if [ "${new_passwd}" = '' ]; then
	echo "new password shold not be empty!"
	exit
fi

for ipAndPort in ${@:3}; do 
	echo "host:${ipAndPort}"
	array=(${ipAndPort//:/ })

	./redis-cli -c -h ${array[0]} -p ${array[1]} -a ${old_passwd} CONFIG SET masterauth ${new_passwd}
	./redis-cli -c -h ${array[0]} -p ${array[1]} -a ${old_passwd} CONFIG SET requirepass ${new_passwd}
	./redis-cli -c -h ${array[0]} -p ${array[1]} -a ${new_passwd} CONFIG REWRITE

done